var path = require('path')
var webpack = require("webpack")
var HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  // 入口文件
  entry: {
    home: [
      './src/views/home-v2/home.js'
    ]
  },
  // 出口文件
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: '[name].[hash].bundle.js',
    chunkFilename: '[name].chunk.js'
  },
  // 加载器配置
  module: {
    rules: [
      { // html加载
        test: /\.html$/,
        use: [
          'raw-loader'
        ]
      },
      { // 样式文件加载
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      { // less文件加载
        test: /\.less$/,
        use:[
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          },
          {
            loader: 'less-loader'
          }
        ]
      },
      { // js文件加载
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      { // 图片、字体资源加载
        test: /\.(png|jpg|gif|svg|ttf|eot|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  // 热加载配置
  devServer: {
    contentBase: "./src/",
    historyApiFallback: true,
    hot: true, // 热加载
    open: true, // 打开浏览器
    inline: true, // 刷新浏览器
    port: 8000 // 端口号
  },
  // 插件配置
  plugins:[
    new webpack.HotModuleReplacementPlugin(), //热加载插件
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
      'window.$': 'jquery',
    }),
    new HtmlWebpackPlugin({
      template: './src/views/home-v2/home.html'
    })
  ]
}
